﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace VSM.Business.Printing.Reports
{
    public delegate void btnViewReport_Click(object sender, System.EventArgs e);

    public partial class CriteriaSummaryOfInventoryCard : System.Web.UI.UserControl
    {
        #region Public Properties

        public DropDownList Warehouse
        {
            get { return ddlWhs; }
        }

        public TextBox FromDate
        {
            get { return txtFromDate; }
        }

        public TextBox ToDate
        {
            get { return txtToDate; }
        }

        #endregion

        #region Public Event
        public event btnViewReport_Click btnViewReportClk;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string dbType = (string)Session[Utils.AppConstants.ID_Dealer] == "VSM" ? Utils.AppConstants.VSM : Utils.AppConstants.DEALER;
                GeneralFunctions GF = new GeneralFunctions(dbType, Session[Utils.AppConstants.ID_Dealer].ToString());
                DataTable dtWhs = null;

                if (!dbType.Equals(Utils.AppConstants.VSM))
                    dtWhs = GF.GetWarehouseByDealerDepartment(dbType, Session[Utils.AppConstants.ID_Dealer].ToString(), Utils.AppConstants.SALES);
                else
                    dtWhs = GF.GetMasterListBySqlCommand(Utils.AppConstants.DEALER, "Select WhsCode, WhsName from OWHS where U_Department = '" + Utils.AppConstants.SALES + "'");

                ddlWhs.DataSource = dtWhs;
                ddlWhs.DataTextField = "WhsName";
                ddlWhs.DataValueField = "WhsCode";
                ddlWhs.DataBind();

                if (dbType.Equals(Utils.AppConstants.VSM))
                {
                    ListItem item = new ListItem("Kho Hồ Chí Minh", "HCM-SAL");
                    ddlWhs.Items.Insert(0, item);
                    item = new ListItem("Kho Hà Nội", "HN-SAL");
                    ddlWhs.Items.Insert(1, item);
                    item = new ListItem("Kho Trưng Bày", "KTB");
                    ddlWhs.Items.Insert(2, item);
                }
            }
        }

        protected void btnViewReport_Click(object sender, EventArgs e)
        {
            //Call Virtual Method
            OnbtnDelQtnMrClk(e);
        }

        #region Vitual Methods
        protected virtual void OnbtnDelQtnMrClk(EventArgs e)
        {
            // Call btnPost_Click event delegate instance
            btnViewReportClk(this, e);
        }
        #endregion

    }
}